import allure

from page.page_index import PageIndex
from page.page_login import PageLogin
from page.page_user import PageUser

#业务类
class ServiceLogin(object):
    def __init__(self,driver,base_url):
        #初始化该业务有关的页面类
        self.page_index=PageIndex(driver,base_url)
        self.page_login=PageLogin(driver,base_url)
        self.page_user=PageUser(driver,base_url)


    def service_login_001(self,d):
        #完成首页页面的操作
        allure.attach("", "打开首页")
        self.page_index.openUrl()
        allure.attach("", "点击首页的登录按钮")
        self.page_index.click_loginButton()

        #完成登录页面的操作
        allure.attach("", "输入账号")
        self.page_login.input_zanhao(d["zanhao"])
        allure.attach("", "输入密码")
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()


        #完成个人中心页面的操作
        siji=self.page_user.getH2Text() #"nswe，欢迎光临"
        yuqi=d["yuqi"]
        # 截图
        imgName=self.page_user.savePng("登录")
        allure.attach(open('./screen/' +imgName+ '.png', 'rb').read(), "本次截图",
                      allure.attachment_type.PNG)

        return siji==yuqi

    def service_login_002(self,d):
        #完成首页页面的操作
        self.page_index.openUrl()
        self.page_index.click_loginButton()

        #完成登录页面的操作
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()

        siji=self.page_login.getDivText() #"账号或密码错误			"
        yuqi=d["yuqi"]
        return yuqi in siji


    def service_login_003(self,d):
        #完成首页页面的操作
        self.page_index.openUrl()
        self.page_index.click_loginButton()

        #完成登录页面的操作
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()

        siji=self.page_login.ZanhaoAttrClass() #"input_text     invalid-text"
        yuqi=d["yuqi"]
        return yuqi in siji

    def service_login_004(self,d):
        #完成首页页面的操作
        self.page_index.openUrl()
        self.page_index.click_loginButton()

        #完成登录页面的操作
        self.page_login.input_zanhao(d["zanhao"])
        self.page_login.input_pwd(d["pwd"])
        self.page_login.click_loginButton()

        siji=self.page_login.pwdAttrClass()
        yuqi=d["yuqi"]
        return yuqi in siji

